//
//  CommonTicketInfo.m
//  EasyToo
//
//  Created by 郑 哲 on 9/6/13.
//
//

#import "CommonTicketInfo.h"

@implementation CommonTicketInfo

- (id)initWithDictionary:(NSDictionary *)jsonDictionary
{
    self = [self init];
    if (self) {        
        NSArray *commonJsonArray = GetDictionaryArrayDefaultNil(jsonDictionary, @"cinemas");
        if (commonJsonArray)
        {
            self.commonCinemaList = [[NSMutableArray alloc] init];
            for (int i = 0; i < [commonJsonArray count]; i++)
            {
                NSDictionary *showDict = [commonJsonArray objectAtIndex:i];
                
                CommonCinemaInfo *commonCinemaInfo = [[CommonCinemaInfo alloc] initWithDictionary:showDict];
                
                NSArray *commonCinemaJsonArray = GetDictionaryArrayDefaultNil(showDict, @"templates");
                for (int j = 0; j < [commonCinemaJsonArray count]; j++) {
                    NSDictionary *cinemaDict = [commonCinemaJsonArray objectAtIndex:j];
                    NSString *tName = GetDictionaryStringDefaultNil(cinemaDict, @"tName");
                    //只展示2D票
                    NSString *prefix = [tName substringToIndex:1];
                    if ([prefix isEqualToString:@"2"]) {
                        commonCinemaInfo.tID = GetDictionaryStringDefaultNil(cinemaDict, @"tID");
                        commonCinemaInfo.tName = GetDictionaryStringDefaultNil(cinemaDict, @"tName");
                        commonCinemaInfo.tTicketDesc = GetDictionaryStringDefaultNil(cinemaDict, @"tTicketDesc");
                        commonCinemaInfo.tMarketPrice = GetDictionaryStringDefaultNil(cinemaDict, @"tMarketPrice");
                        commonCinemaInfo.tMinPrice = GetDictionaryStringDefaultNil(cinemaDict, @"tMinPrice");
                        commonCinemaInfo.tEnableDay = GetDictionaryStringDefaultNil(cinemaDict, @"tEnableDay");
                        commonCinemaInfo.tInvalidationDate = GetDictionaryStringDefaultNil(cinemaDict, @"tInvalidationDate");
                        break;
                    }
                }
                
                [self.commonCinemaList addObject:commonCinemaInfo];
            }
        }
        
    }
    return self;
}
@end

@implementation CommonCinemaInfo

- (id)initWithDictionary:(NSDictionary *)jsonDictionary
{
    self = [self init];
    if (self) {
        self.address = GetDictionaryStringDefaultNil(jsonDictionary, @"address");
        self.cinemadesc = GetDictionaryStringDefaultNil(jsonDictionary, @"cinemadesc");
        self.cinemaid = GetDictionaryStringDefaultNil(jsonDictionary, @"cinemaid");
        self.cinemaname = GetDictionaryStringDefaultNil(jsonDictionary, @"cinemaname");
        self.cityid = GetDictionaryStringDefaultNil(jsonDictionary, @"cityid");
        self.cityname = GetDictionaryStringDefaultNil(jsonDictionary, @"cityname");
        self.contactphone = GetDictionaryStringDefaultNil(jsonDictionary, @"contactphone");
        self.detail = GetDictionaryStringDefaultNil(jsonDictionary, @"detail");
        
        self.preferential = GetDictionaryStringDefaultNil(jsonDictionary, @"preferential");
        self.regionname = GetDictionaryStringDefaultNil(jsonDictionary, @"regionname");
        self.statflag = GetDictionaryStringDefaultNil(jsonDictionary, @"statflag");
    }
    return self;
}

@end
